import request from '@/utils/request'
// import qs from 'qs'

// 获取防御策略列表
export function getFloodArray (params) {
  var data = fromData(params)
  return request({
    url: '/ddos/getFloodArray',
    method: 'post',
    data
  })
}

// 增加防御策略
export function addFlood (params) {
  var data = fromData(params)
  return request({
    url: '/ddos/addFlood',
    method: 'post',
    data
  })
}

// 编辑防御策略
export function editFlood (params) {
  var data = fromData(params)
  return request({
    url: '/ddos/editFlood',
    method: 'post',
    data
  })
}

// 获取防御策略信息
export function getFloodInfo (params) {
  var data = fromData(params)
  return request({
    url: '/ddos/getFloodInfo',
    method: 'post',
    data
  })
}

// 删除Flood防御策略
export function delFlood (params) {
  var data = fromData(params)
  return request({
    url: '/ddos/del_flood',
    method: 'post',
    data
  })
}

// 获取基本配置
export function getFloodBaseInfo (params) {
  var data = fromData(params)
  return request({
    url: '/ddos/getFloodBaseInfo',
    method: 'post',
    data
  })
}

// 修改基本配置
export function setFloodBaseInfo (params) {
  var data = fromData(params)
  return request({
    url: '/ddos/setFloodBaseInfo',
    method: 'post',
    data
  })
}

// 获取防御策略黑名单
export function getCategoryBlack (params) {
  var data = fromData(params)
  return request({
    url: '/ddos/getCategoryBlack',
    method: 'post',
    data
  })
}

// 清空防御策略黑名单
export function cleanCategoryBlack (params) {
  var data = fromData(params)
  return request({
    url: '/ddos/cleanCategoryBlack',
    method: 'post',
    data
  })
}

// 获取防御类别信息
export function getCategory (params) {
  var data = fromData(params)
  return request({
    url: '/ddos/getCategory',
    method: 'post',
    data
  })
}

// 编辑防御类别
export function editCategory (params) {
  var data = fromData(params)
  return request({
    url: '/ddos/editCategory',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
